package com.example.mrzhou.lvmm.view.fragment.surround;


import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.example.mrzhou.lvmm.R;
import com.example.mrzhou.lvmm.commom.base.BaseFragment;
import com.example.mrzhou.lvmm.commom.utils.FragmentViewPagerUtils;
import com.example.mrzhou.lvmm.entity.surround.holiday.Holiday;
import com.example.mrzhou.lvmm.entity.surround.hotel.Hotel;
import com.example.mrzhou.lvmm.entity.surround.scenic.Scenic;
import com.example.mrzhou.lvmm.view.activity.MapActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * A simple {@link Fragment} subclass.
 */
public class SurroundFragment extends BaseFragment {
    @BindView(R.id.tab_surround)
    TabLayout tabSurround;
    @BindView(R.id.vp_surround)
    ViewPager vpSurround;
    private List<Fragment> fragments;
    public static final String[] TITLE = {"景点", "酒店", "度假"};

    private Scenic scenic;
    private Hotel hotel;
    private Holiday holiday;


    public SurroundFragment() {
        // Required empty public constructor
    }

    public static SurroundFragment newInstance() {

        Bundle args = new Bundle();

        SurroundFragment fragment = new SurroundFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_surround;
    }

    @Override
    protected void initView(View view) {
        ButterKnife.bind(this, view);
        initData();
        FragmentViewPagerUtils utils = new FragmentViewPagerUtils();
        utils.fragmentVpUtils(fragments, TITLE, vpSurround, tabSurround, getChildFragmentManager());
    }


    @Override
    protected void initData() {
        fragments = new ArrayList<>();
        fragments.add(SurScenicFragment.newInstance(new SurScenicFragment.OnScenicCallBack() {
            @Override
            public void onScenicCallBack(Scenic scenic) {
                SurroundFragment.this.scenic = scenic;
            }
        }));
        fragments.add(SurHotelFragment.newInstance(new SurHotelFragment.OnSurHotelCallBack() {
            @Override
            public void onSurHotelCallBack(Hotel hotel) {
                SurroundFragment.this.hotel = hotel;
            }
        }));
        fragments.add(SurHolidayFragment.newInstance(new SurHolidayFragment.OnSurHolidayCallBack() {
            @Override
            public void onSurHolidayCallBack(Holiday holiday) {
                SurroundFragment.this.holiday = holiday;
            }
        }));
    }

    @OnClick(R.id.iv_surround)
    public void onClick() {
        switch (vpSurround.getCurrentItem()) {
            case 0:
                if (this.scenic != null) {
                    Intent intent = new Intent(getContext(), MapActivity.class);
                    intent.putExtra("type", 0);
                    intent.putExtra("scenic", scenic);
                    getContext().startActivity(intent);
                }
                break;
            case 1:
                if (this.hotel != null) {
                    Intent intent = new Intent(getContext(), MapActivity.class);
                    intent.putExtra("type", 1);
                    intent.putExtra("hotel", hotel);
                    getContext().startActivity(intent);
                }
                break;
            case 2:
                if (this.holiday != null) {
                    Intent intent = new Intent(getContext(), MapActivity.class);
                    intent.putExtra("type", 2);
                    getContext().startActivity(intent);
                }
                break;
        }
    }
}
